package com.yanqu.road.server.logic.recharge.limit.activity;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.jinli.config.JinLiConfig;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.entity.mall.LimitBuyResult;
import com.yanqu.road.logic.helper.ActivityHelper;
import com.yanqu.road.server.gameplayer.module.activity.jinli.JinLiModule;
import com.yanqu.road.server.manger.activity.jinli.JinLiMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.protocol.GameErrorCode;

public class JinLiRmbMallLimit extends BaseActivityMallLimit {

    public JinLiRmbMallLimit(long userId, MallInfo mallInfo, ActivityInfo activityInfo) {
        super(userId, mallInfo, activityInfo);
    }

    @Override
    protected int activityCheck() {
        JinLiConfig config = JinLiMgr.getConfig();
        if (config == null) {
            return GameErrorCode.E_ACTIVITY_NOT_OPEN;
        }
        if (!ActivityHelper.activityInTime(config.getActivityInfo())) {
            return GameErrorCode.E_ACTIVITY_NOT_OPEN;
        }
        return 0;
    }

    @Override
    protected boolean isSystemUnLock() {
        JinLiConfig config = JinLiMgr.getConfig();
        if (config == null) {
            return false;
        }
        return SystemOpenMgr.systemOpen(player, eSystemId.JinLi.getValue()) && player.getUserInfo().getTitleId() >= config.getLvLimit();
    }

    @Override
    protected LimitBuyResult buyCountLimit() {
        return activityMallCountLimit(player);
    }

    @Override
    protected int logicCheck() {
        if (!player.getModule(JinLiModule.class).canCharge(mallInfo.getMallId())) {
            return GameErrorCode.E_MALL_LIMIT_BUY;
        }
        return 0;
    }
}
